package com.wbp.cms.core.project.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.wbp.cms.client.project.domain.ProjectWorkOrderDO;
import com.wbp.cms.client.project.query.ProjectWorkOrderQuery;
import com.wbp.cms.client.project.service.ProjectWorkOrderSerivce;
import com.wbp.cms.client.result.Result;
import com.wbp.cms.core.project.dao.ProjectWorkOrderDAO;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月9日 下午3:08:50
 */
@Service("projectWorkOrderSerivce")
public class ProjectWorkOrderServiceImpl implements ProjectWorkOrderSerivce {
  /**
   * 
   */
  private static final long serialVersionUID = -1805754748488538509L;

  @Resource(name="projectWorkOrderDAO")
  private ProjectWorkOrderDAO  projectWorkOrderDAO ;
  
  @Override
  public Result<Long> addProjectWorkOrder(ProjectWorkOrderDO projectWorkOrderDO) {
    Preconditions.checkNotNull(projectWorkOrderDO, "projectWorkOrderDO不能为null") ;
    return  Result.buildSuccess(projectWorkOrderDAO.insert(projectWorkOrderDO)) ;
  }
   
  @Override
  public Result<Boolean> modifyProjectWorkOrder(ProjectWorkOrderDO projectWorkOrderDO) {
    Preconditions.checkNotNull(projectWorkOrderDO, "projectWorkOrderDO不能为null") ;
    return Result.buildSuccess(projectWorkOrderDAO.update(projectWorkOrderDO) > 0 );
  }
   
  @Override
  public Boolean deleteProjectWorkOrderByProject(Long projectId) {
    return null;
  }
   
  @Override
  public Result<List<ProjectWorkOrderDO>> queryProjectWorkOrderByProject(Long projectId) {
    Preconditions.checkNotNull(projectId, "projectId:"+projectId+",不能为null") ;
    Preconditions.checkArgument(projectId > 0 , "projectId:"+projectId+",应该 >0 ") ;
    ProjectWorkOrderQuery  projectWorkOrderQuery =new ProjectWorkOrderQuery();
    projectWorkOrderQuery.setProjectId(projectId); 
     return queryProjectWorkOrderByProject(projectWorkOrderQuery) ;
  }

   
  @Override
  public Result<List<ProjectWorkOrderDO>> queryProjectWorkOrderByProject(ProjectWorkOrderQuery q) {
    int count = this.projectWorkOrderDAO.queryCount(q) ;
    List<ProjectWorkOrderDO> list =null ;
    if(count > 0){
      list = this.projectWorkOrderDAO.query(q) ;
    }
    return Result.buildSuccess(count, list);
  }
  

}
